package com.swjd.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.util.ArrayList;



import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		
		// doGET 说明采用的 GET 方式 来请求数据

		
		// request 通过请求对象，获取浏览器传递过来的信息
		//    http://localhost:6666/shop/servlet/LoginServlet?u=zhangsan
		//  获取 GET 数据中名称为 u 的值   zhangsan  类型是字符串
		//    定义1个字符串变量 username 等于获取到前端的参数 u
		//String username = request.getParameter("u");
		
		String username = new String(request.getParameter("u").getBytes("ISO8859-1"), "UTF-8");
		
		//username = URLDecoder.decode(username, "UTF-8");
		
		// 取p的值
		String password = request.getParameter("p");
		
		
		
		
		
		// 购物车 数据
		
		
		
		
		// response 相当于向浏览器发送内容的1个系统对象，响应对象
		
		//  通过 response 对象，获取到一个 I/O 对象
		PrintWriter out = response.getWriter();

		
		
	    // 向浏览器输出内容
		out.print("Hi ~~~~  ");
		// 向浏览器输出 username的值
		out.print(username);

		// 向浏览器输出 passord的值
		out.print(password);
		
		// 刷新出去
		out.flush();
		// 关闭 I/O 流
		out.close();
	}

}
